package com.example.w.web.controller;

import com.example.w.common.dto.TableAddDTO;
import com.example.w.common.pojo.Table;
import com.example.w.common.util.Result;
import com.example.w.service.TableManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/table")
@Api(tags = "桌台管理接口")
public class TableController {

    @Autowired
    private TableManagerService tableManagerService;

    /**
     添加餐桌
     */
    @PostMapping("/addTable")
    @ApiOperation("添加餐桌")
    public Result addTable(@RequestBody TableAddDTO tableAddDTO) {
        Table target=new Table();
        BeanUtils.copyProperties(tableAddDTO,target);
        Integer id=tableManagerService.addTable(target);
        return new Result(true, "添加成功", id);
    }

    /**
     更新餐桌
     */
    @GetMapping("/updateTable")
    @ApiOperation("更新餐桌状态，0表示空，1表示有人")
    public Result updateTableStatus(@RequestParam int tableNumber, boolean occupied){
        Table target=new Table();
        tableManagerService.updateTableStatus(tableNumber, occupied);
        return new Result(true, "更新成功");
    }

    /**
     删除餐桌
     */
    @PostMapping("/removeTable")
    @ApiOperation("删除餐桌")
    public Result removeTable(@RequestBody int tableId){
        tableManagerService.removeTable(tableId);
        return new Result(true,"删除成功");
    }

    /**
     * 查询餐桌信息
     */
    @GetMapping("getTableInfo")
    @ApiOperation("查询桌子信息")
    public Result getTableInfo() {
        return new Result(true, "查询成功", tableManagerService.selectTable());
    }

}
